#!/bin/sh

#Sunucu İp Ayarla 1.0
#Bilgisayar Agi Paket Sayaci

clear
echo "************************************************ "
echo "****************** SUNUCU AYAR ***************** "
echo "************************************************ "

ip="192.168.1.246"

#otomatik olarak ip'yi öğren
OS=`uname`
ip="" # store IP
   subnetmask=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f4 | awk '{ print $1}'`
   subnet=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f3 | awk '{ print $1}'`

case $OS in
   Linux) ip=`ifconfig  | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;
   FreeBSD|OpenBSD) ip=`ifconfig  | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;
   SunOS) ip=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;
   *) ip="Unknown";;
esac
echo "ip: $ip"
echo "subnet: $subnet"
echo "subnetmask: $subnetmask"

# LAN SUPPORT Conf Değişkenleri
#------------------------------
lan_char_ip=$ip 
lan_map_ip=$ip 

#------------------------------
#------------------------------
# CHAR ATHENA Conf Değişkenleri
#------------------------------
login_ip=$ip
login_port="9601"
char_ip=$ip
char_port="9602"
#------------------------------
#------------------------------
# LOGIN ATHENA Conf Değişkenleri
#------------------------------
# login_port="9601" üstte tanımlandı...
#------------------------------
#------------------------------
# MAP ATHENA Conf Değişkenleri
#------------------------------
#char_ip="192.168.1.241" üstte tanımlandı...
#char_port="9602" üstte tanımlandı...
map_ip=$ip
map_port="9603"
#------------------------------

lan_support_conf=`cat lan_support.conf`
char_athena_conf=`cat char_athena.conf`
login_athena_conf=`cat login_athena.conf`
map_athena_conf=`cat map_athena.conf`

############ lan_support.conf
sed "s/lan_char_ip:.*/lan_char_ip: $lan_char_ip/g" lan_support.conf > lan_support2.conf
mv lan_support2.conf lan_support.conf

sed "s/lan_map_ip:.*/lan_map_ip: $lan_map_ip/g" lan_support.conf > lan_support2.conf
mv lan_support2.conf lan_support.conf

sed "s/subnet:.*/subnet: $subnet/g" lan_support.conf > lan_support2.conf
mv lan_support2.conf lan_support.conf

sed "s/subnetmask:.*/subnetmask: $subnetmask/g" lan_support.conf > lan_support2.conf
mv lan_support2.conf lan_support.conf
############ char_athena.conf
sed "s/login_ip:.*/login_ip:$login_ip/g" char_athena.conf > yedek.conf
mv yedek.conf char_athena.conf

sed "s/login_port:.*/login_port: $login_port/g" char_athena.conf > yedek.conf
mv yedek.conf char_athena.conf

sed "s/char_ip:.*/char_ip:$char_ip/g" char_athena.conf > yedek.conf
mv yedek.conf char_athena.conf

sed "s/char_port:.*/char_port: $char_port/g" char_athena.conf > yedek.conf
mv yedek.conf char_athena.conf
############ login_athena.conf
sed "s/login_port:.*/login_port: $login_port/g" login_athena.conf > yedek.conf
mv yedek.conf login_athena.conf
############ map_athena.conf
sed "s/char_ip:.*/char_ip:$char_ip/g" map_athena.conf > yedek.conf
mv yedek.conf map_athena.conf

sed "s/char_port:.*/char_port: $char_port/g" map_athena.conf > yedek.conf
mv yedek.conf map_athena.conf

sed "s/map_ip:.*/map_ip:$map_ip/g" map_athena.conf > yedek.conf
mv yedek.conf map_athena.conf

sed "s/map_port:.*/map_port: $map_port/g" map_athena.conf > yedek.conf
mv yedek.conf map_athena.conf

chown elektrogame lan_support.conf
chmod 755 lan_support.conf

chown elektrogame char_athena.conf
chmod 755 char_athena.conf

chown elektrogame login_athena.conf
chmod 755 login_athena.conf

chown elektrogame map_athena.conf
chmod 755 map_athena.conf
####################################################
